package cn.wildfire.chat.kit.user;

import android.content.Intent;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.kyleduo.switchbutton.SwitchButton;
import com.sourcemuch.im.caiba.R;import com.sourcemuch.im.caiba.R2;

import butterknife.BindView;
import butterknife.OnClick;
import cn.wildfire.chat.app.extendsion.ui.ToastTip;
import cn.wildfire.chat.app.main.ChooseUsercardReceiverActivity;
import cn.wildfire.chat.kit.WfcBaseActivity;
import cn.wildfirechat.model.UserInfo;
import cn.wildfirechat.remote.ChatManager;
import cn.wildfirechat.remote.GeneralCallback;

/**
 * Create by HEKE, 2019/9/23 17:17
 * TODO 资料设置
 */
public class FriendDataSettingActivity extends WfcBaseActivity {

    @BindView(R2.id.tv_recommend_to)
    TextView tvRecommendTo;
    @BindView(R2.id.sb_join_blacklist)
    SwitchButton sbJoinBlacklist;

    private UserInfo friendUserInfo;

    @Override
    protected int contentLayout() {
        return R.layout.activity_friend_data_setting;
    }

    @Override
    protected void afterViews() {
        super.afterViews();
        friendUserInfo = getIntent().getParcelableExtra("userInfo");
        sbJoinBlacklist.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ChatManager.Instance().setBlackList(friendUserInfo.uid, isChecked, new GeneralCallback() {
                    @Override
                    public void onSuccess() {
                        if(isChecked){
                            ToastTip.tip(getString(R.string.join_blacklist_success));
                        }else{
                            ToastTip.tip(getString(R.string.move_out_from_blacklist_success));
                        }
                    }

                    @Override
                    public void onFail(int errorCode) {
                        ToastTip.tip(getString(R.string.join_blacklist_failure));
                    }
                });
            }
        });
        boolean isBlackFriend = ChatManager.Instance().isMyBlackList(friendUserInfo.uid);
        sbJoinBlacklist.setCheckedNoEvent(isBlackFriend);
    }

    @Override
    protected void setTitleCenterThenSetSearchView() {
        super.setTitleCenterThenSetSearchView();
        setToolbarOrReplaceType(true, 3);
        setReplaceTitle(getTitle().toString(), -1);
        setSearchLayoutVisibility(false);
    }

    @OnClick(R2.id.tv_recommend_to)
    public void onViewClicked() {
        Intent intent = new Intent(this, ChooseUsercardReceiverActivity.class);
        intent.putExtra("friendUserInfo", friendUserInfo);
        startActivity(intent);
        finish();
    }

}


